package com.dataSructure.tree;

public class ArrBinaryTreeCreate {
    
    private static int length = 0;
    private static int[] arr = new int[]{1,2,3,4,5,6,7,8,9};


    public static void main(String[] args) {

        HeroNode heroNode = new HeroNode(0, arr[0] + "");

        preOrder(0, heroNode);
        System.out.println(heroNode);
    }

    public static void preOrder(int index, HeroNode heroNode) {
        if (arr == null || arr.length == 0) {
            System.out.println("数组为空，不能按照二叉树的前序遍历");
        }
        System.out.println(heroNode);

        if (index * 2 + 1 < arr.length) {
            
            HeroNode heroNode1 = new HeroNode(2 * index + 1,arr[2 * index + 1] + "");
            heroNode.setLeft(heroNode1);
            preOrder(2 * index + 1,heroNode1);
        }
        
        if (index * 2 + 2 < arr.length) {
            HeroNode heroNode2 = new HeroNode(2 * index + 2,arr[2 * index + 2] + "");
            heroNode.setRight(heroNode2);
            preOrder(2 * index + 2,heroNode2);
        }
    }
}
